package com.aisile.crowd_funding.system.service.impl;

import com.aisile.crowd_funding.system.mapper.SysUserMapper;
import com.aisile.crowd_funding.system.pojo.SysUser;
import com.aisile.crowd_funding.system.pojo.SysUserExample;
import com.aisile.crowd_funding.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static com.aisile.crowd_funding.system.pojo.SysUserExample.*;

/**
 * @标题 UserServiceImpl
 * @作者 Mr.chen
 * @创建日期 2018/12/5 16:43
 * @版本号 1.0
 **/
@Service
@Transactional
public class UserServiceImpl implements UserService{
    @Autowired
    SysUserMapper sysUserMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        return sysUserMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(SysUser record) {
        return sysUserMapper.insert(record);
    }

    @Override
    public SysUser selectByPrimaryKey(Long id) {
        return sysUserMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKey(SysUser sysUser) {
        return sysUserMapper.updateByPrimaryKey(sysUser);
    }

    @Override
    public List<SysUser> selectByExample(SysUserExample sysUserExample) {
        return sysUserMapper.selectByExample(sysUserExample);
    }

    @Override
    public SysUser findByUserName(String userName) {
        SysUserExample sysUserExample = new SysUserExample();
        sysUserExample.createCriteria().andUsernameEqualTo(userName);
        List<SysUser> sysUsers = sysUserMapper.selectByExample(sysUserExample);
        if(sysUsers!=null&&sysUsers.size()>0){
            return sysUsers.get(0);
        }
        return null;
    }
}
